package com.es.estatemanagement;


import com.auth0.jwt.JWT;
import com.auth0.jwt.JWTVerifier;
import com.auth0.jwt.algorithms.Algorithm;
import com.auth0.jwt.interfaces.DecodedJWT;
import com.es.estatemanagement.domain.*;
import com.es.estatemanagement.mapper.EstateRightMapper;
import com.es.estatemanagement.mapper.LoginLogMapper;
import com.es.estatemanagement.mapper.SurveyAnswersMapper;
import com.es.estatemanagement.service.BuildingService;
import com.es.estatemanagement.service.HouseService;
import com.es.estatemanagement.service.impl.EstateManagerServiceImpl;
import com.es.estatemanagement.service.impl.OwnerServiceImpl;
import com.github.pagehelper.Page;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.security.core.userdetails.UserDetails;
import org.springframework.test.context.junit4.SpringRunner;

import java.io.IOException;
import java.util.Calendar;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

@RunWith(SpringRunner.class)
@SpringBootTest
public class test {

    /**
     * http://www.8414525.com/job/kp_details.html?id=375
     * http://www.jianelec.com/technology/zhihuiwuyessm-cn.html
     */

    @Autowired
    EstateManagerServiceImpl estateManagerService;

    @Autowired
    private HouseService houseService;

    @Autowired
    EstateRightMapper estateRightMapper;

    @Autowired
    private OwnerServiceImpl ownerService;


    @Test
    public void testHouse() {
        Map searchMap = new HashMap();
        //"startTime":"","endTime":"","name":"","pageNum":1,"pageSize":2
        searchMap.put("startTime", "");
        searchMap.put("endTime", "");
        searchMap.put("name", "");
        searchMap.put("pageNum", "1");
        searchMap.put("pageSize", "2");
        searchMap.put("pageNum", 1);
        searchMap.put("pageSize", 2);
        Page<House> page = houseService.search(searchMap);
        System.out.println(page);
    }

    @Test
    public void testO() {
//        List<Owner> all = ownerService.findAll();
//        String s = "";
//        for (Owner o : all) {
//            s += "{\"value\":\"" + o.getName() + "\"},";
//        }
//        System.out.println(s.substring(0, s.length() - 1));
//        String pwd = BCrypt.hashpw("123456", BCrypt.gensalt());
//        System.out.println(pwd);
    }

    @Test
    public void test1() {
//        List<EstateRight> list=estateRightMapper.findAllByEstateRight("15900000000");
//        System.out.println(list);
    }


    @Test
    public void testJWT() {
        Map<String, Object> map = new HashMap<>();
        Calendar calendar = Calendar.getInstance();
        calendar.add(Calendar.SECOND, 200);
        String token = JWT.create()
                .withHeader(map) //header
                .withClaim("userId", "12") //payload
                .withClaim("password", "123456")
                .withExpiresAt(calendar.getTime())
                .sign(Algorithm.HMAC256("!Q@W#E$R"));

        System.out.println(token);
    }

    @Test
    public void testVer() {
        JWTVerifier jwtVerifier = JWT.require(Algorithm.HMAC256("!Q@W#E$R")).build();
        DecodedJWT verify = jwtVerifier.verify("eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJsb2dpbk5hbWUiOiIxNTkwMDAwMDAwMCIsImV4cCI6MTY2ODc0MTU5M30.LtwixT4amv8hk2Yg_u2-HSn1mpjVirZom0yd0IqB0HQ");
        System.out.println(verify.getClaim("loginName").asString());
//        System.out.println(verify.getClaim("password").asString());
        System.out.println(verify.getExpiresAt()); //过期时间

    }


    @Autowired
    SurveyAnswersMapper surveyAnswersMapper;

    @Test
    public void tests() {
        SurveyAnswers surveyAnswers = surveyAnswersMapper.selectByPrimaryKey(1);
        System.out.println(surveyAnswers);
    }


    @Autowired
    BuildingService buildingService;
    @Test
    public void sssss() throws IOException {
//        com.hospital.configer.GetIp getIp=new com.hospital.configer.GetIp();
//        System.out.println(getIp.getV4OrV6IP());
//        System.out.println(getIp.getNameAddress());
    }

}
